package cn.fan.redis;

import cn.fan.mapper.TaskRemindMapper;
import cn.fan.pojo.TaskRemind;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class TaskRemindRedis {
    private static final String TASKREMIND = "taskremind";
    private static final String TASKREMINDLIST = "taskremind:list";

    @Autowired
    private TaskRemindMapper taskRemindMapper;

    @Cacheable(value = TASKREMIND,key = "#id")
    public TaskRemind getById(int id){
        return taskRemindMapper.selectById(id);
    }

    @CachePut(value = TASKREMIND,key = "#id")
    public TaskRemind putById(int id){
        return taskRemindMapper.selectById(id);
    }

    @CachePut(value = TASKREMIND,key = "#id")
    public TaskRemind putById(int id,TaskRemind TaskRemind){
        return TaskRemind;
    }

    @CacheEvict(value = TASKREMIND,key = "#id")
    public void delete(int id){}

    // list
    @Cacheable(value = TASKREMINDLIST ,key = "#userId")
    public List<TaskRemind> getList(long userId){
        LambdaQueryWrapper<TaskRemind> queryWrapper = new LambdaQueryWrapper<TaskRemind>();
        queryWrapper.eq(TaskRemind::getCreateBy,userId);
        List<TaskRemind> list = taskRemindMapper.selectList(queryWrapper);
        return list;
    }

    @CachePut(value = TASKREMINDLIST,key = "#userId")
    public List<TaskRemind> putList(long userId){
        LambdaQueryWrapper<TaskRemind> queryWrapper = new LambdaQueryWrapper<TaskRemind>();
        queryWrapper.eq(TaskRemind::getCreateBy,userId);
        List<TaskRemind> list = taskRemindMapper.selectList(queryWrapper);
        return list;
    }

    @CachePut(value = TASKREMINDLIST,key = "#userId")
    public List<TaskRemind> putList(List<TaskRemind> TaskReminds){
        return TaskReminds;
    }

    @CacheEvict(value = TASKREMINDLIST,key = "#userId")
    public void deleteList(){}
}
